﻿@{
    ViewBag.Title = "数据字典";
}
@section headerSection{
    <link href="~/Resources/mainFrame/js/plugins/zTree3/css/demo.css" rel="stylesheet" />
    <link href="~/Resources/mainFrame/js/plugins/zTree3/css/metroStyle/metroStyle.css" rel="stylesheet" />
    <script src="~/Lang/GetLangData"></script>
    <script src="~/Resources/mainFrame/js/plugins/zTree3/js/jquery.ztree.core.min.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/zTree3/js/jquery.ztree.excheck.min.js"></script>
    <script src="~/Resources/mainFrame/js/plugins/zTree3/js/jquery.ztree.exedit.min.js"></script>
    <script src="~/Resources/tools/search_zTree.js"></script>
    <script src="~/Resources/tools/HRHelp.js"></script>
    <style>
        body {
            font-family: '微软雅黑';
            font-size: 14px;
            color: #676a6c;
        }

        #exampleToolbar div {
            margin-bottom: 0px;
        }

        #exampleToolbar > .form-group {
            float: left;
            margin: 0;
            margin-right: 5px;
            margin-top: 1px;
        }

        .form-group > button {
            margin-top: -2px;
            margin-bottom: 2px;
        }

        #unitTreezTreeData {
            border: 0;
            border-top: 1px solid #E7EAEC;
            background: #FFFFFF;
        }

            #unitTreezTreeData li {
                line-height: 28px;
            }

                #unitTreezTreeData li:hover {
                    background: #F5F5F5;
                }

        #dictFormTable, #dictFormTable > .form-group {
            margin: 0;
        }

        #dictFormChildTable, #dictFormChildTable > .form-group {
            margin: 0;
        }
    </style>
}
<div class="wrapper animated fadeInRight autoHeight">
    <!-- Panel Other -->
    <div class="row autoHeight" style="background-color: #fff;">
        <!--Tree选择-->
        <div id="unitTree" class="col-sm-3" style="width:220px;height:100%;padding:0;border:1px solid #E7EAEC;"></div>
        <div class="col-sm-9 col-sm-leftRight" style="width: calc(100% - 220px);padding-left: 3px; margin-top: 2px;">
            <!-- Example Toolbar -->
            <div class="example">
                <div class="btn-group hidden-xs" id="exampleToolbar" role="group">
                    @{
                        List<string> folderList = (List<string>)ViewBag.elementList;
                        if (folderList.Contains("dictAddPeer"))
                        {
                            <button id="dictAddPeer" type="button" title="添加根" class="btn btn-outline btn-primary">
                                <i class="glyphicon glyphicon-list" aria-hidden="true"></i>添加根字典
                            </button>
                        }
                        if (folderList.Contains("dictAddChild"))
                        {
                            <button id="dictAddChild" type="button" title="添加子" class="btn btn-outline btn-primary">
                                <i class="glyphicon glyphicon-list-alt" aria-hidden="true"></i>添加字典下拉
                            </button>
                        }
                        @*if (folderList.Contains("dictEdit"))
                            {
                                <button id="dictEdit" type="button" class="btn btn-outline btn-primary">
                                    <i class="glyphicon glyphicon-pencil" aria-hidden="true">编辑</i>
                                </button>
                            }*@
                        if (folderList.Contains("dictDel"))
                        {
                            <button id="dictDel" type="button" class="btn btn-outline btn-danger">
                                <i class="glyphicon glyphicon-trash" aria-hidden="true">删除</i>
                            </button>
                        }
                        if (folderList.Contains("btnSearch"))
                        {
                            <div class="form-group" style="width:200px;margin-top:-1px;">
                                <input id="keyword" name="keyword" type="text" class="form-control" placeholder="字典名称/字典代码">
                            </div>
                            <div class="form-group" style="margin-top:-1px;">
                                <button id="btnSearch" class="btn btn-primary" type="button"><i class="fa fa-search"></i>&nbsp;查询</button>
                            </div>
                        }
                        if (folderList.Contains("btnUpLogo"))
                        {
                            <div class="form-group" style="margin-top:-1px;">
                                <button type="button" id="btnUpLogo" class="btn btn-primary" style="margin-left: 2px;"><i class="glyphicon glyphicon-circle-arrow-up"></i>上传Logo</button>
                            </div>
                        }
                        if (folderList.Contains("btnExport"))
                        {
                            <div class="form-group" style="margin-top:-1px;">
                                <button id="btnExport" class="btn btn-primary" type="button"><i class="fa fa-pencil"></i>&nbsp;导出Execl</button>
                            </div>
                        }
                    }
                </div>
                <table id="exampleTableToolbar" data-mobile-responsive="true" data-radio="true" style="table-layout: fixed !important;"></table>
            </div>
            <!-- End Example Toolbar -->
        </div>
    </div>
    <!-- End Panel Other -->
</div>
<!--添加/编辑根节点-->
<div id="EditDictMain" class="form-group" style="overflow: hidden; display: none;">
    <form class="form-horizontal m-t row" id="dictFormTable" method="post">
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">名称<i class="glyphicon glyphicon-asterisk" style="color:red;"></i></label>
            <div class="col-sm-4">
                <input type="text" id="item_name" name="item_name" class="form-control" placeholder="名称" />
                <input type="hidden" id="item_id" name="item_id" />
                <input type="hidden" id="code_pid" name="code_pid" value="0" />
            </div>
            <label class="col-sm-2 control-label">代码<i class="glyphicon glyphicon-asterisk" style="color:red;"></i></label>
            <div class="col-sm-4">
                <input type="text" id="item_code" name="item_code" class="form-control" placeholder="代码" />
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">条件值</label>
            <div class="col-sm-4">
                <input type="text" id="whereValue" name="whereValue" class="form-control" placeholder="条件值" />
            </div>
            <label class="col-sm-2 control-label codeType">数量值</label>
            <div class="col-sm-4">
                <input type="text" id="numValue" name="numValue" class="form-control codeType" placeholder="数量值" />
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">英文名称</label>
            <div class="col-sm-10">
                <input type="text" id="enLang" name="enLang" class="form-control" placeholder="英文名称" />
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">备注</label>
            <div class="col-sm-10" style="padding-left:15px; padding-right:15px;">
                <textarea id="item_note" name="item_note" class="form-control" placeholder="备注"></textarea>
            </div>
        </div>
        <div class="hr-line-dashed"></div>
    </form>
</div>
<!--添加/编辑子节点-->
<div id="EditDictChild" class="form-group" style="overflow: hidden; display: none;">
    <form class="form-horizontal m-t row" id="dictFormChildTable" method="post">
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">名称<i class="glyphicon glyphicon-asterisk" style="color:red;"></i></label>
            <div class="col-sm-4">
                <input type="text" id="itemName" name="itemName" class="form-control" placeholder="名称" />
                <input type="hidden" id="itemId" name="itemId" />
                <input type="hidden" id="codePid" name="codePid" value="0" />
            </div>
            <label class="col-sm-2 control-label">代码<i class="glyphicon glyphicon-asterisk" style="color:red;"></i></label>
            <div class="col-sm-4">
                <input type="text" id="itemCode" name="itemCode" class="form-control" placeholder="代码" />
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">条件值</label>
            <div class="col-sm-4">
                <input type="text" id="codeType" name="codeType" class="form-control" placeholder="条件值" />
            </div>
            <label class="col-sm-2 control-label codeType">数量值</label>
            <div class="col-sm-4">
                <input type="text" id="numValue2" name="numValue2" class="form-control codeType" placeholder="数量值" />
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">英文名称</label>
            <div class="col-sm-4">
                <input type="text" id="enLang2" name="enLang2" class="form-control" placeholder="英文名称" />
            </div>
            <label class="col-sm-2 control-label">序号</label>
            <div class="col-sm-4">
                <input type="text" id="codeOrder" name="codeOrder" class="form-control" placeholder="序号" />
            </div>
        </div>
        <div class="hr-line-dashed"></div>
        <div class="form-group">
            <label class="col-sm-2 control-label">备注</label>
            <div class="col-sm-10" style="padding-left:15px; padding-right:15px;">
                <textarea id="itemNote" name="itemNote" class="form-control" placeholder="备注"></textarea>
            </div>
        </div>
        <div class="hr-line-dashed"></div>
    </form>
</div>
<!--Logo图片-->
<div id="orgLogo" style="width: 460px; overflow: hidden; display: none;">
    <form class="form-horizontal m-t" id="orgLogoForm" method="post" enctype="multipart/form-data" style="padding-bottom:20px;">
        <div class="form-group">
            <label class="col-sm-3 control-label">图片<span class="glyphicon glyphicon-asterisk requiredtitle"></span>：</label>
            <div class="col-sm-7">
                <input type="file" id="logo_img" name="logo_img" placeholder="请选择logo图片的" class="form-control" required="" aria-required="true">
            </div>
        </div>
    </form>
</div>
@section footSection{
    <script src="~/Resources/x-editable/js/bootstrap-editable.js"></script>
    <script>
        var $table, unitzTree, options,//树控件缩略图
            item_id = 0,
            selNode,//选中节点
            isType,//树类别
            $addOrEditUrl;
        var dictManager = {
            //1.0 初始化页面
            initPage: function () {
                dictManager.initTable();
                dictManager.bindZtree();
                dictManager.bindEvent();
            },
            //1.1 采用Ztree初始化文档树
            bindZtree: function () {
                if (unitzTree)
                    unitzTree.destroy();
                var setting = {
                    view: {
                        showIcon: true,
                        selectedMulti: false,
                        fontCss: getFontCss
                    },
                    edit: {
                        enable: true,
                        showRemoveBtn: false,
                        showRenameBtn: false
                    },
                    async: {
                        enable: true,
                        dataType: "text",
                        type: "post",
                        url: ctx + "/SysItemCode/GetDocTreeData",
                        autoParam: ["id"]
                    },
                    data: {
                        key: { title: "name", name: "name" },
                        simpleData: { enable: true, idKey: "id", pIdKey: "pId", rootPId: 0 }
                    },
                    check: {
                        enable: false,
                        autoCheckTrigger: true,
                        chkStyle: "checkbox",
                        chkboxType: { "Y": "p", "N": "ps" }
                    },
                    callback: {
                        onAsyncError: function () {
                            layer.msg("初始化字典树失败~", { icon: 5 });
                        },
                        onAsyncSuccess: function (event, treeId, treeNode, msg) {
                            //树加载完成后执行
                            //var obj = unitzTree.getNodes()[0];
                            //if (obj) {
                            //    unitzTree.selectNode(obj);
                            //    unitzTree.setting.callback.onClick(null, unitzTree.setting.treeId, obj);//模拟点击事件
                            //    if (obj.children && obj.children.length > 0)
                            //        unitzTree.expandNode(obj);
                            //}
                        },
                        onClick: function (event, treeId, treeNode) {
                            //$('#unitTree a').css("color", "#333");
                            //$('#' + treeNode.tId + '_a').css("color", "#ffffff");
                            //checkNodeSpan = treeNode.tId + '_span';
                            selNode = treeNode;//选中节点
                            item_id = treeNode.id;
                            if ($table && treeNode.id > 0)
                                $table.bootstrapTable('refresh', options);//刷新Table
                        },
                        //拖拽回调
                        //beforeDrag: function (treeId, treeNodes) {
                        //    for (var i = 0, l = treeNodes.length; i < l; i++) {
                        //        if (!treeNodes[i].drag)
                        //            return false;
                        //    }
                        //    return true;
                        //},
                        beforeDrop: function (treeId, treeNodes, targetNode, moveType) {
                            return targetNode ? targetNode.drop !== false : true;
                        }
                    }
                };
                unitzTree = $("#unitTree").initzTreeView(setting, 'ushow', false);
                unitzTree.setting.edit.drag.isCopy = false;
                unitzTree.setting.edit.drag.isMove = true;
                unitzTree.setting.edit.drag.prev = true;
                unitzTree.setting.edit.drag.inner = false;
                unitzTree.setting.edit.drag.next = true;
            },
            //初始化Table
            initTable: function () {
                options = {
                    url: ctx + "/SysItemCode/GetDictData",
                    cutHeight: 5,
                    showRefresh: false,
                    showToggle: false,
                    showColumns: false,
                    singleSelect: false,
                    uniqueId: "item_id",
                    toolbar: "#exampleToolbar",
                    queryParams: function (params) {
                        dictManager.getClickTree();
                        params = {
                            rows: params.limit,
                            //页面大小
                            page: params.offset / params.limit + 1,
                            keyword: ($("#keyword").val()) ? encodeURIComponent($("#keyword").val()) : "",//代码
                            item_id: item_id, //字典主表id
                            isType: isType
                        }
                        return params;
                    },
                    columns: [
                        {
                            checkbox: true
                        },
                        {
                            field: '',//第一列序号
                            title: '序号',
                            align: 'center',
                            width: 55,
                            formatter: function (value, row, index) {
                                return index + 1;
                            }
                        }, {
                            field: 'item_id',
                            title: '操作',
                            align: 'center',
                            width: 55,
                            formatter: function (value, row, index) {
                                return "<button class=\"btn btn-info btn-circle btn-outline\" title='编辑' onclick=\"dictManager.editItemCode(" + row.item_id + ")\" type=\"button\"><i class=\"fa fa-pencil\"></i></button>";
                            }
                        },
                        {
                            field: 'code_pid',
                            title: '类别',
                            align: 'center',
                            width: 80,
                            formatter: function (value, row, index) {
                                if (row.isParent)
                                    return "<font color='red'>根字典</font>";
                                return "<font color='green'>字典项</font>";
                            }
                        }, {
                            field: 'logoUrl',
                            title: '图片',
                            align: 'center',
                            width: 110,
                            formatter: function (value, row, index) {
                                if (value)
                                    return "<img title='点击上传图片' onclick=dictManager.uploadPic(" + row.item_id + "," + row.isParent + ") src='" + value.toString().replace("~", window.location.origin + ctx) + "' style='width:70px;height:60px;' />";
                                return "<button title='点击上传图片' onclick=dictManager.uploadPic(" + row.item_id + "," + row.isParent + ") class='btn btn-primary btn-circle btn-outline'><i class=\"fa fa-picture-o\"></i></button>";
                            }
                        },
                        {
                            field: 'item_name',
                            title: '名称',
                            align: 'center',
                            width: 140
                        }, {
                            field: 'item_code',
                            title: '代码',
                            align: 'center',
                            width: 130
                        }, {
                            field: 'whereValue',
                            title: '条件值',
                            align: 'center',
                            width: 80
                        }, {
                            field: 'numValue',
                            title: '数量值',
                            align: 'center',
                            width: 80
                        }, {
                            field: 'enLang',
                            title: '英文名',
                            align: 'center',
                            width: 120
                        }, {
                            field: 'code_order',
                            title: '序号',
                            align: 'center',
                            width: 50,
                            formatter: function (value, row, index) {
                                return value ? value : "";
                            }
                        }, {
                            field: 'item_note',
                            title: '备注',
                            align: 'left',
                            width: 200,
                            formatter: function (value, row, index) {
                                if (value && value.length > 45)
                                    return "<span title='" + value + "'>" + value.substring(0, 45) + "...</span>";
                                return value;
                            }
                        }, {
                            field: 'create_date',
                            title: '创建时间',
                            align: 'center',
                            width: 150
                        }, {
                            field: 'update_date',
                            title: '更新时间',
                            align: 'center',
                            width: 150
                        }]
                }
                $table = tableHelper.initTable("exampleTableToolbar", options);
            },
            //上传下拉图片
            uploadPic: function (item_id, isParent) {
                $('#logo_img').val('');
                if (!item_id)
                    return false;
                //0：根，1：子节点
                var root = isParent ? 0 : 1;
                layer.open({
                    title: ['上传图片', 'font-size:18px;'],
                    type: 1,
                    content: $('#orgLogo'),
                    scroll: false,//是否显示滚动条、默认不显示
                    btn: ['确定', '取消'],
                    area: ['480px', '250px'],
                    yes: function (li, o) {
                        var logo_img = $('#logo_img').val();
                        if (!logo_img) {
                            layer.alert("请选择图片！", { icon: 3 });
                            return false;
                        }
                        $('#orgLogoForm').ajaxSubmit({
                            url: $.ctx() + '/Main/UploadLogo',
                            type: "post",
                            dataType: "json",
                            data: { "item_id": item_id, "root": root },
                            beforeSubmit: function (arr, $form, options) {
                                layer.msg("提交数据~", { icon: 1, time: 5000 });
                            },
                            success: function (result, status, xhr, $form) {
                                layer.closeAll();
                                if (result.Statu === 0)
                                    //刷新列表
                                    $table.bootstrapTable('refresh', options);
                                else
                                    layer.alert(result.Msg, { icon: 5 });
                            },
                            error: function (xhr, status, error, $form) {
                                layer.msg("保存失败~", { icon: 5 });
                            }
                        });
                    }
                });
            },
            //绑定默认事件
            bindEvent: function () {
                //上传logo
                $('#btnUpLogo').on('click', function () {
                    $('#logo_img').val('');
                    layer.open({
                        title: ['上传logo', 'font-size:18px;'],
                        type: 1,
                        content: $('#orgLogo'),
                        scroll: false,//是否显示滚动条、默认不显示
                        btn: ['确定', '取消'],
                        area: ['480px', '250px'],
                        yes: function (li, o) {
                            var logo_img = $('#logo_img').val();
                            if (!logo_img) {
                                layer.alert("请选择logo图片！", { icon: 3 });
                                return false;
                            }
                            $('#orgLogoForm').ajaxSubmit({
                                url: $.ctx() + '/Main/UploadLogo',
                                type: "post",
                                dataType: "json",
                                beforeSubmit: function (arr, $form, options) {
                                    layer.msg("提交数据~", { icon: 1, time: 5000 });
                                },
                                success: function (result, status, xhr, $form) {
                                    layer.closeAll();
                                    if (result.Statu === 0)
                                        //更新logo地址
                                        $('#logoUrl', parent.document).attr("src", result.Data.toString().replace("~", $.ctx()));
                                    else
                                        layer.alert(result.Msg, { icon: 5 });
                                },
                                error: function (xhr, status, error, $form) {
                                    layer.msg("保存失败~", { icon: 5 });
                                }
                            });
                        }
                    });
                });
                //添加根字典
                $('#dictAddPeer').on('click', function () {
                    dictManager.addEditNode(null, true);
                });
                //添加子节点
                $('#dictAddChild').on('click', function () {
                    dictManager.addEditNode(null, false);
                });
                //编辑
                $('#dictEdit').on('click', function () {
                    var row = dictManager.selections();
                    if (!row)
                        return false;
                    dictManager.addEditNode(row, row.isParent);
                });
                //删除
                $('#dictDel').on('click', function () {
                    var row = dictManager.selections();
                    if (!row)
                        return false;
                    dictManager.deleteNode(row.item_id, row.isParent);
                });
                //查询
                $('#btnSearch').on('click', function () {
                    $table.bootstrapTable('refresh', options);
                });
                //导出
                $('#btnExport').on('click', function () {
                    layer.alert("待开发......", { icon: 3 });
                    return false;
                });
            },
            //编辑字典
            editItemCode: function (item_id) {
                if (!item_id)
                    return false;
                var row = $table.bootstrapTable('getRowByUniqueId', item_id);
                if (!row)
                    return false;
                dictManager.addEditNode(row, row.isParent);
            },
            //删除
            deleteNode: function (item_id, isParent) {
                if (!item_id || item_id <= 0) {
                    layer.alert("待删除的数据关键字异常！", { icon: 5 });
                    return false;
                }
                layer.confirm('您确定要删除当前选中记录？', {
                    btn: ['确定', '取消'] //按钮
                }, function () {
                    var index = layer.msg("删除中...", { icon: 6, time: 6000 });
                    $.ajax({
                        type: 'post',
                        url: ctx + '/SysItemCode/DelDictById/' + item_id,
                        dataType: 'json',
                        data: { isType: (isParent) ? "itemCode" : "" },
                        async: false,
                        success: function (data) {
                            layer.close(index);
                            if (data.Statu === 0) {
                                layer.msg("删除成功...");
                                $table.bootstrapTable('refresh', options);
                                var zTree = $.fn.zTree.getZTreeObj("unitTreezTreeData"),
                                    removeNode = zTree.getNodeByParam("id", item_id);
                                if (removeNode)
                                    zTree.removeNode(removeNode);
                            }
                            else
                                layer.msg(data.Msg, { icon: 5 });
                        }
                    });
                }, function () { });
            },
            //添加、编辑【节点】
            addEditNode: function (e, isRoot) {
                var zTree = $.fn.zTree.getZTreeObj("unitTreezTreeData"),
                    nodes = zTree.getSelectedNodes(),
                    treeNode = nodes[0];
                var title = "", addNode;
                if (!isRoot && !nodes[0].id) {
                    layer.alert("添加子字典请先选中根节点！", { icon: 3 });
                    return false;
                }
                if (!e) {
                    if (isRoot) {
                        title = "添加根字典";
                        $addOrEditUrl = ctx + "/SysItemCode/AddNode";
                        addNode = null;
                    } else {
                        title = "添加子字典";
                        $addOrEditUrl = ctx + "/SysItemCode/AddChildNode";
                        addNode = treeNode;
                    }
                }
                else {
                    if (isRoot) {
                        title = "编辑根字典";
                        $addOrEditUrl = ctx + "/SysItemCode/EditNode";
                    }
                    else {
                        title = "编辑子字典";
                        $addOrEditUrl = ctx + "/SysItemCode/EditChildNode";
                    }
                }
                //清空form
                if (isRoot) {
                    $('#dictFormTable').resetHideValidForm();//根节点
                    //打开编辑根节点
                    layer.open({
                        title: [title, 'font-size:18px;'],
                        type: 1,
                        content: $('#EditDictMain'),
                        scroll: true,//是否显示滚动条、默认不显示
                        btn: ["保存", "取消"],
                        area: ['700px', '550px'],
                        success: function (li, o) {
                            if (e) {
                                $('#dictFormTable')[0].reset();//重置表单
                                $('#dictFormTable').LoadForm(e);//表单填充数据
                            }
                        },
                        yes: function (li, o) {
                            if (!$('#item_name').val() || !$('#item_code').val()) {
                                layer.msg("温馨提示：名称和代码不允许为空！");
                                return false;
                            }
                            if ($('#dictFormTable').valid()) {
                                //验证通过
                                $('#dictFormTable').ajaxSubmit({
                                    url: $addOrEditUrl,
                                    type: "post",
                                    data: { isType: (isRoot) ? "itemCode" : "", main_id: item_id },
                                    dataType: "json",
                                    beforeSubmit: function (arr, $form, options) {
                                        layer.msg("提交数据~", { icon: 1, time: 5000 });
                                    },
                                    success: function (result, status, xhr, $form) {
                                        if (result.Statu === 0) {
                                            layer.closeAll();
                                            var nodes = result.Data;
                                            if (!e) {
                                                //添加
                                                zTree.addNodes(addNode, { id: nodes.item_id, name: nodes.item_name, isRoot: isRoot, enLang: nodes.enLang, pId: nodes.code_pid, itemNote: nodes.item_note, open: false, children: null });
                                            } else {
                                                //编辑
                                                var editNode = zTree.getNodeByParam("id", e.item_id, null);
                                                editNode.name = nodes.item_name;
                                                editNode.enLang = nodes.enLang;
                                                editNode.pId = nodes.code_pid;
                                                editNode.itemNote = nodes.item_note;
                                                zTree.updateNode(editNode);
                                            }
                                            //重置选中树对应的Table
                                            $table.bootstrapTable('refresh', options);
                                        } else
                                            layer.alert(result.Data, { icon: 5 });
                                    },
                                    error: function (xhr, status, error, $form) {
                                        layer.msg("保存失败~", { icon: 5 });
                                    }
                                });
                            }
                        },
                        cancel: function (li, o) {
                        }
                    });
                } else {
                    $('#dictFormChildTable').resetHideValidForm();//子节点
                    //打开编辑子节点
                    layer.open({
                        title: [title, 'font-size:18px;'],
                        type: 1,
                        content: $('#EditDictChild'),
                        scroll: true,//是否显示滚动条、默认不显示
                        btn: ["保存", "取消"],
                        area: ['700px', '550px'],
                        success: function (li, o) {
                            if (e) {
                                $('#dictFormChildTable')[0].reset();//重置表单
                                //$('#dictFormChildTable').LoadForm(e);//表单填充数据
                                $('#itemName').val(e.item_name);
                                $('#itemId').val(e.item_id);
                                $('#codePid').val(e.code_pid);
                                $('#itemCode').val(e.item_code);
                                $('#codeType').val(e.code_type);
                                $('#numValue2').val(e.numValue);
                                $('#enLang2').val(e.enLang);
                                $('#codeOrder').val(e.code_order);
                                $('#itemNote').val(e.item_note);
                            }
                        },
                        yes: function (li, o) {
                            if (!isRoot && e && e.code_pid > 0)
                                $('#codePid').val(e.code_pid);
                            if (!$('#itemName').val() || !$('#itemCode').val()) {
                                layer.msg("温馨提示：名称和代码不允许为空！");
                                return false;
                            }
                            if ($('#dictFormChildTable').valid()) {
                                //验证通过
                                $('#dictFormChildTable').ajaxSubmit({
                                    url: $addOrEditUrl,
                                    type: "post",
                                    data: { isType: (isRoot) ? "itemCode" : "", main_id: item_id },
                                    dataType: "json",
                                    beforeSubmit: function (arr, $form, options) {
                                        layer.msg("提交数据~", { icon: 1, time: 5000 });
                                    },
                                    success: function (result, status, xhr, $form) {
                                        if (result.Statu === 0) {
                                            layer.closeAll();
                                            var nodes = result.Data;
                                            if (!e) {
                                                //添加
                                                zTree.addNodes(addNode, { id: nodes.item_id, name: nodes.item_name, isRoot: isRoot, enLang: nodes.enLang, pId: nodes.code_pid, itemNote: nodes.item_note, open: false, children: null });
                                            } else {
                                                //编辑
                                                var editNode = zTree.getNodeByParam("id", e.item_id, null);
                                                editNode.name = nodes.item_name;
                                                editNode.enLang = nodes.enLang;
                                                editNode.pId = nodes.code_pid;
                                                editNode.itemNote = nodes.item_note;
                                                zTree.updateNode(editNode);
                                            }
                                            //重置选中树对应的Table
                                            $table.bootstrapTable('refresh', options);
                                        } else
                                            layer.alert(result.Data, { icon: 5 });
                                    },
                                    error: function (xhr, status, error, $form) {
                                        layer.msg("保存失败~", { icon: 5 });
                                    }
                                });
                            }
                        },
                        cancel: function (li, o) {
                        }
                    });
                }
            },
            //获取选中行数据
            selections: function (isAll) {
                var row = $table.bootstrapTable('getSelections');
                if (!row || row.length === 0) {
                    layer.msg("数据为空或未选中记录行~", { icon: 5 });
                    return false;
                }
                if (isAll)
                    return row;
                if (row.length > 1) {
                    layer.msg("当前操作不支持多选，请选择一行再操作！", { icon: 5 });
                    return false;
                }
                return row[0];
            },
            //获取树被选中id
            getClickTree: function () {
                var zTree = $.fn.zTree.getZTreeObj("unitTreezTreeData"),
                    nodes = null;
                if (zTree)
                    nodes = zTree.getSelectedNodes();
                if (nodes && nodes.length > 0) {
                    selNode = nodes[0];
                    item_id = selNode.id;
                    isType = selNode.isRoot ? "itemCode" : "menuCode";
                    return selNode;
                } else {
                    selNode = null;
                    item_id = 0;
                    isType = "";
                    return null;
                }
            }
        }
        $(function () {
            dictManager.initPage();
        });
    </script>
}